package cont

type CategoryNode struct {
	Category
	Children []CategoryNode `json:"children"`
}

// 指定根节点数据和要挂载的数据，返回挂载好的树和剩余数据
func HangCategoryNode(root Category, data []Category) (CategoryNode, []Category) {
	node := CategoryNode{Category: root, Children:make([]CategoryNode, 0)}
	remaining := make([]Category, 0)
	for _, item := range data {
		if item.ParentID == root.ID {
			var node2 CategoryNode
			node2, remaining = HangCategoryNode(item, data)
			node.Children = append(node.Children, node2)
		} else {
			remaining = append(remaining, item)
		}
	}
	return node, remaining
}